Skip to content

Cache /_astro/ files for a day instead of a year - #49

Merged
meaningfool merged 2 commits into
mainfrom
claude/blissful-cori-0j27kf
Nov 19, 2026
Merged

meaningfool merged 2 commits into
mainfrom
claude/blissful-cori-0j27kf

Conversation

@meaningfool

@meaningfool meaningfool commented Nov 19, 2026 •

Copy link
Copy Markdown
Owner

Problem

public/_headers gives /_astro/* Cache-Control: public, max-age=31536000, immutable. Cloudflare sends that header with the 404 for a missing file too:

curl -sI https://meaningfool.net/_astro/does-not-exist.abc123.css
HTTP/2 404
content-type: text/html
cache-control: public, max-age=31536000, immutable

Right after #48 deployed, the first load of /apps/one-light-day/ got its new stylesheet back as a 404 page, probably from a Cloudflare server still on the previous version. This can happen in the seconds after any deploy that adds files to /_astro/: a new app, a style change, or a new article with images. Only the visitor's browser keeps the 404, not Cloudflare, but it can keep it for a year.

Change

/_astro/* now gets Cache-Control: public, max-age=86400, so browsers keep these files for a day.

  • A 404 served in that window disappears from the browser within a day at most.
  • Without immutable, reloading the page in Firefox or Safari checks the files again, which fixes it sooner.
  • Cost: after a day, a returning visitor's browser asks whether each file changed and gets a short 304 back instead of the file. These are static-asset requests, so they're free and unlimited.

AGENTS.md and the comment in public/_headers explain why it's a day.

The first commit, since undone: it ran the Worker for every /_astro/* request so it could send no-store on 404s only. That kept the year-long caching, but every request for these files would have counted toward the Worker's daily limit on the Free plan, which was out of proportion with how rare the problem is. The second commit restores wrangler.jsonc and worker/index.js exactly as they are on main.

Checks

  • Build: diff -r against a build of main with the same content shows only dist/_headers, which Cloudflare reads but never serves, and the Generated: timestamps in llms.txt and llms-full.txt. Every page is identical.

  • Headers, compared with main under wrangler dev: only /_astro/ responses changed. These went from public, max-age=31536000, immutable to public, max-age=86400:

    • an existing file: GET 200, HEAD 200 and If-None-Match 304
    • POST: 405
    • the 404s for a missing file and for /_astro/

    Pages, redirects, /rss.xml, video byte ranges and the other 404s are unchanged.

  • bun run test:documents: 12 passed.

To check on the preview:

curl -sI https://pr-49-meaningfool.josselin-perrus.workers.dev/_astro/does-not-exist.abc123.css

This should return 404 with cache-control: public, max-age=86400.

🤖 Generated with Claude Code

https://claude.ai/code/session_013MdjUbV3zudUd8ZBxydwBu

public/_headers gives /_astro/* a year of immutable caching, and Cloudflare
adds it to the 404 for a missing file too. Right after a deploy, a page can
ask for a new stylesheet from an edge that still serves the previous version;
the browser could then keep that 404 for a year.

Run the Worker first for /_astro/* as well as /images/*. It passes every
response on as the assets serve it, except a 404, which gets
Cache-Control: no-store.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013MdjUbV3zudUd8ZBxydwBu
@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Preview: https://pr-49-meaningfool.josselin-perrus.workers.dev

Built from c656779 with the latest content. The link stays the same and shows the latest push. Search engines are asked not to index it.

Running the Worker for every /_astro/ request was out of proportion with the
problem: it counts each of those requests toward the Worker's limits. Undo
that, and instead shorten the caching public/_headers gives /_astro/* from a
year (immutable) to a day. A 404 served in the seconds after a deploy then
stays in a browser for a day at most, and reloading the page in Firefox or
Safari checks it again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013MdjUbV3zudUd8ZBxydwBu
@meaningfool meaningfool changed the title Stop caching 404s under /_astro/ for a year Cache /_astro/ files for a day instead of a year Nov 19, 2026
@meaningfool
meaningfool merged commit 183a5fd into main Nov 19, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants